package com.wfc.servlet.dish;

import com.wfc.service.DishService;
import com.wfc.service.serviceImpl.DishServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteDish")
public class deleteDish extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id1 = req.getParameter("id");
        int id = 0;
        if (!"null".equals(id1)){
            id = Integer.parseInt(id1);
        }

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        DishService dishService = new DishServiceImpl();
        int i = dishService.deleteById(id);
        String mess="";
        PrintWriter writer = resp.getWriter();

        if(i>0){
            mess="删除成功！";
        }else {
            mess="删除失败！";
        }
        writer.println(mess);
        writer.flush();
        writer.close();
    }
}
